package junit;


import heli.SunCalculations;
import junit.framework.TestCase;

public class JulianDateTC extends TestCase {
	
public void test_JD() {
	
	//Date,Time (Universal Time); MET would be actually 8h) 
	int year=2011;
	int month=2;
	int day=20;
	int hour=7;
	int minute=24;
	int second=0;
	
	double jd=SunCalculations.toJulian_JD(year, month, day, hour, minute, second);
	System.out.println("toJulian_JD():"+jd);
	assertTrue(java.lang.Math.abs(jd-2455612.84553)<0.01);
	
}

/**Data from http://de.wikipedia.org/wiki/Sonnenstand, Beispiel */	
public void test_SunCalculations() {
	
	//Date,Time (Universal Time); MET would be actually 8h) 
	int year=2006;
	int month=8;
	int day=6;
	int hour=6;
	int minute=0;
	int second=0;
	
	//geocodes for Munich
	double phi=48.1; //N
	double lambda=11.6; //O
	
	double jd=SunCalculations.toJulian_JD(year, month, day, hour, minute, second);
	System.out.println("toJulian_JD(2006, 8, 6, 6, 0, 0):"+jd);
	assertTrue(java.lang.Math.abs(jd-2453953.75)<0.001);
	
	double jd0=SunCalculations.toJulian_JD(2006, 8, 6, 0, 0, 0);
	System.out.println("toJulian_JD0(2006, 8, 6, 0, 0, 0):"+jd0);
	assertTrue(java.lang.Math.abs(jd0-2453953.5)<0.001);
	
	double n = SunCalculations.days_since_J2000_n(jd);
	System.out.println("days_since_J2000_n(jd):"+n);
	assertTrue(java.lang.Math.abs(n-2408.75)<0.001);	
	
	double g = SunCalculations.med_anomaly_g_raw(n);
	System.out.println("med_anomaly_g_raw(n):"+g);
	assertTrue(java.lang.Math.abs(g-2731.593)<0.001);
	g = SunCalculations.med_anomaly_g(n);
	System.out.println("med_anomaly_g(n):"+g);
	assertTrue(java.lang.Math.abs(g-211.593)<0.001);
	
	double L = SunCalculations.med_ecl_L_raw(n);
	System.out.println("med_ecl_L_raw(n):"+L);	
	assertTrue(java.lang.Math.abs(L-2654.638)<0.001);
	L = SunCalculations.med_ecl_L(n);
	System.out.println("med_ecl_L(n):"+L);	
	assertTrue(java.lang.Math.abs(L-134.638)<0.001);
	
	double Lambda = SunCalculations.med_ecl_length_Lambda(g, L);
	System.out.println("med_ecl_length_Lambda(g, L):"+Lambda);
	assertTrue(java.lang.Math.abs(Lambda-133.653)<0.001);
	
	double epsilon = SunCalculations.ecliptic_epsilon(n);
	System.out.println("ecliptic_epsilon(n):"+epsilon);
	assertTrue(java.lang.Math.abs(epsilon-23.438)<0.001);
	
	double alpha = SunCalculations.right_ascension(epsilon, Lambda);
	System.out.println("right_ascension(epsilon, Lambda):"+alpha);
	assertTrue(java.lang.Math.abs(alpha-136.119)<0.001);	
	
	double delta = SunCalculations.declination_delta(epsilon, Lambda);
	System.out.println("declination_delta(epsilon, Lambda):"+delta);
	assertTrue(java.lang.Math.abs(delta-16.726)<0.001);
	
	double T0 = SunCalculations.T0(jd0);
	System.out.println("T0(jd0):"+T0);
	assertTrue(java.lang.Math.abs(T0-0.06594113621)<0.00000000001);
	
	double theta__h_G = SunCalculations.average_sidereal_time_hourly_theta__h_G_raw(T0, hour, minute, second);
	System.out.println("average_sidereal_time_hourly_theta__h_G_raw(T0, 0):"+theta__h_G);
	assertTrue(java.lang.Math.abs(theta__h_G-170.9759)<0.0001);
	
	theta__h_G = SunCalculations.average_sidereal_time_hourly_theta__h_G(T0, hour, minute, second);
	System.out.println("average_sidereal_time_hourly_theta__h_G(T0, 0):"+theta__h_G);
	assertTrue(java.lang.Math.abs(theta__h_G-2.9759)<0.0001);
	
	double theta = SunCalculations.hour_angle_of_equinox_theta(theta__h_G, lambda);
	System.out.println("hour_angle_of_equinox_theta(theta__h_G, lambda):"+theta);
	assertTrue(java.lang.Math.abs(theta-56.239)<0.001);
	
	double tau = SunCalculations.hour_angle_of_location_tau(theta, alpha);
	System.out.println("hour_angle_of_location_tau(theta, alpha):"+tau);	
	
	double azimuth_A = SunCalculations.azimuth_A(tau, phi, delta);
	System.out.println("azimuth(tau, phi, delta):"+azimuth_A);
	assertTrue(java.lang.Math.abs(azimuth_A-(-94.062))<0.001);
	
	double elevation_h = SunCalculations.elevation_h(tau, phi, delta);
	System.out.println("elevation_h(tau, phi, delta):"+elevation_h);
	assertTrue(java.lang.Math.abs(elevation_h-19.062)<0.001);
	
	double elevation_h_R = SunCalculations.elevation_refrCorrection_h_R(elevation_h);
	System.out.println("elevation_refrCorrection_h_R(elevation_h):"+elevation_h_R);
	assertTrue(java.lang.Math.abs(elevation_h_R-19.11)<0.001);
	
}

public void test_SunCalculations2() {
	
	//Date,Time (Universal Time); MET would be actually 8h) 
	int year=2006;
	int month=8;
	int day=6;
	int hour=6;
	int minute=0;
	int second=0;
	
	//geocodes for Munich
	double phi=48.1; //N
	double lambda=11.6; //O
	
	double jd=SunCalculations.toJulian_JD(year, month, day, hour, minute, second);
	
	double jd0=SunCalculations.toJulian_JD(2006, 8, 6, 0, 0, 0);
	
	double n = SunCalculations.days_since_J2000_n(jd);
	
	double g = SunCalculations.med_anomaly_g_raw(n);	
	g = SunCalculations.med_anomaly_g(n);
	
	double L = SunCalculations.med_ecl_L_raw(n);	
	L = SunCalculations.med_ecl_L(n);
	
	double Lambda = SunCalculations.med_ecl_length_Lambda(g, L);
	
	double epsilon = SunCalculations.ecliptic_epsilon(n);
	
	double alpha = SunCalculations.right_ascension(epsilon, Lambda);
	
	
	double delta = SunCalculations.declination_delta(epsilon, Lambda);
	
	
	double T0 = SunCalculations.T0(jd0);
	
	double theta__h_G = SunCalculations.average_sidereal_time_hourly_theta__h_G_raw(T0, hour, minute, second);
	
	theta__h_G = SunCalculations.average_sidereal_time_hourly_theta__h_G(T0, hour, minute, second);
	
	double theta = SunCalculations.hour_angle_of_equinox_theta(theta__h_G, lambda);
	
	double tau = SunCalculations.hour_angle_of_location_tau(theta, alpha);
	
	double azimuth_A = SunCalculations.azimuth_A(tau, phi, delta)+180;
	double azimuthVonNorden=SunCalculations.azimuthFromNorth(azimuth_A);
	System.out.println("azimuth(tau, phi, delta):"+azimuthVonNorden);
	
	double elevation_h = SunCalculations.elevation_h(tau, phi, delta);
	System.out.println("elevation_h(tau, phi, delta):"+elevation_h);
	
	double elevation_h_R = SunCalculations.elevation_refrCorrection_h_R(elevation_h);
	System.out.println("elevation_refrCorrection_h_R(elevation_h):"+elevation_h_R);
	
}

public void test_SimpleDaysSince1J2000() {

	System.out.println(SunCalculations.to_JDN(2000, 1, 1, 10, 0, 0));	
	System.out.println(SunCalculations.to_SimpleDSince1J2000(2000, 1, 1, 10, 0, 0));
	
}

public void test_SimpleJDN() {	
	
	assertEquals(      SunCalculations.to_JDN(2011, 0, 24, 10, 0, 0),
			     SunCalculations.to_SimpleJDN(2011, 0, 24, 10, 0, 0));
	
	assertEquals(      SunCalculations.to_JDN(2020, 5, 24, 11, 0, 0),
		         SunCalculations.to_SimpleJDN(2020, 5, 24, 10, 0, 0));
	
	assertEquals(      SunCalculations.to_SimpleJDN2(2020, 5, 24, 11, 0, 0),
	             SunCalculations.to_SimpleJDN(2020, 5, 24, 10, 0, 0));
	
	assertEquals(      SunCalculations.to_JDN(2099, 5, 24, 11, 0, 0),
	             SunCalculations.to_SimpleJDN(2099, 5, 24, 10, 0, 0));
	
	assertEquals(      SunCalculations.to_JDN(2051, 1, 1, 11, 0, 0),
            SunCalculations.to_SimpleJDN(2051, 1, 1, 10, 0, 0));
	
	//simplified Formula not correct any more
	//assertEquals(      SunCalculations.to_JDN(2100, 5, 24, 11, 0, 0),
    //        SunCalculations.to_SimpleJDN(2100, 5, 24, 10, 0, 0));
	
	
}

public void test_azimuth() {
	//Date,Time (Universal Time); MET would be actually 8h) 
	int year=2006;
	int month=8;
	int day=6;
	int hour=6;
	int minute=0;
	int second=0;
	
	//geocodes for Munich
	double phi=48.1; //N
	double lambda=11.6; //O
	
	double azimuth=SunCalculations.azimuth(year, month, day, hour, minute, second, phi, lambda);
	System.out.println("azimuth(year, month, day, hour, minute, second, phi, lambda):"+azimuth);
	assertTrue(java.lang.Math.abs(azimuth-(-94.062))<0.001);
	
}

public void test_elevation() {
	//Date,Time (Universal Time); MET would be actually 8h) 
	int year=2006;
	int month=8;
	int day=6;
	int hour=6;
	int minute=0;
	int second=0;
	
	//geocodes for Munich
	double phi=48.1; //N
	double lambda=11.6; //O
	
	double elevation=SunCalculations.elevation(year, month, day, hour, minute, second, phi, lambda);
	System.out.println("elevation(year, month, day, hour, minute, second, phi, lambda):"+elevation);
	assertTrue(java.lang.Math.abs(elevation-19.11)<0.001);
	
}
	
}
